<template>
  <div class="gjcgl_box">
    <header-comm></header-comm>
    <div class="bcg">
      <div class="header_sele">
        <div class="add_qy">
          <a-button type="primary" @click="tjwz">添加</a-button>
          <a-button type="primary" @click="getkeywords">关键词采集</a-button>
          <a-button type="primary" @click="yjcx">一键查询</a-button>
        </div>
        <div>
          <div class="gl_tjwz" v-if="$store.state.tjwz">
            <addkeytk class="gl_tjym"></addkeytk>
          </div>
          <div class="seach">
            <div class="sele">
              <a-input placeholder="请输入关键词 " style="width: 250px" @change="onSearch" />
              <a-icon type="search" class="search" />
            </div>
          </div>
        </div>
      </div>
      <div class="glwz">
        <a-table
          @change="handleChangelist"
          :loading="loading"
          :columns="columns"
          :pagination="pagination"
          :dataSource="data"
          :rowSelection="rowSelection"
        >
          <template slot="pic" slot-scope="text, record, index">
            <div>
              <img
                class="glwzpic"
                :src="`https://image.bearing.cn/qy/member/`+record.sqdwid+`/`+record.pic"
                alt
              />
            </div>
          </template>

          <!-- <template slot="operation" slot-scope="text, record, index">
          <div class="editable-row-operations">
            <a class="del" @click="()=>xiugai(record,record.key)">修改</a>
            <a-popconfirm class="del" title="确定删除吗?" @confirm="() => wzdelete(record,record.key)">
              <a>删除</a>
            </a-popconfirm>
          </div>
          </template>-->
        </a-table>
        <div class="del_all">
          <a-button type="primary" @click="showModal">批量删除</a-button>
          <a-modal
            title="Title"
            :visible="visible"
            @ok="start"
            :confirmLoading="confirmLoading"
            @cancel="handleCancel"
          >
            <p>确认删除吗？</p>
          </a-modal>
        </div>
      </div>
      <div class="mode" v-if="spin">
        <a-spin tip="查询中..."></a-spin>
      </div>
    </div>

    <!-- 表格-================= -->
  </div>
</template>

<script>
import addkeytk from "./addkeytk.vue";
import headerComm from "../header-comm/header.vue";

const columns = [
  {
    title: "关键词",
    dataIndex: "keywords"
  },
  {
    title: "百度PC排名",
    dataIndex: "id_num",
    scopedSlots: { customRender: "id_num" }
  },
  {
    title: "查看",
    dataIndex: "domain"
  },
  {
    title: "采集时间",
    dataIndex: "datetime"
  }
  // {
  //   title: "操作",
  //   dataIndex: "operation",
  //   scopedSlots: { customRender: "operation" }
  // }
];
const data = [];

import qs from "qs";
import { setTimeout } from "timers";
export default {
  data() {
    this.cacheData = data.map(item => ({ ...item }));

    return {
      data,
      columns,
      sele: "",
      serchvalue: "",
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0
      },
      loading: true,
      selectedRowKeys: [],
      visible: false,
      confirmLoading: false,
      // fldatalist: [],
      spin: false
    };
  },
  components: {
    addkeytk,
    headerComm
    // xzl
  },
  methods: {
    //搜索框
    onSearch(e) {
      this.serchvalue = e.target.value;
      this.handleChangelist(this.pagination, this.serchvalue);
    },

    //获取关键词列表
    handleChangelist(pagination, khmc) {
      this.axios
        .post(
          "seo/KeyWordsList.php",
          qs.stringify({
            page: pagination.current,
            pageSize: pagination.defaultPageSize,
            sqdwid: this.$store.state.bbl_sqdwid,
            field: khmc
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.data = res.data.result.data;
            this.pagination.total = Number(res.data.result.total);
            this.loading = false;
            this.cacheData = this.data.map(item => ({
              ...item
            }));
            for (var i = 0; i < res.data.result.data.length; i++) {
              this.data[i].key = res.data.result.data[i].id_num;
            }
          } else {
            this.data = [];
            this.loading = false;
          }
        });
    },

    //确认批量删除
    showModal() {
      if (this.selectedRowKeys.length) {
        this.visible = true;
      } else {
        this.visible = false;
        this.$notification["error"]({
          message: "失败",
          description: "请先选择要删除的列表",
          duration: 1.5
        });
      }
    },
    handleCancel(e) {
      this.visible = false;
    },

    //批量删除
    start() {
      const newData = [...this.data];
      let selectedRowKeys = this.selectedRowKeys;
      this.axios
        .post(
          "seo/KeyWordsBatchDelete.php",
          qs.stringify({
            id_num: selectedRowKeys
          })
        )
        .then(res => {
          //更新数据成功
          if (res.data.code == 303) {
            this.loading = false;
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg,
              duration: 1.5
            });
            selectedRowKeys.map(rowkeys => {
              this.data = this.data.filter(item => item.key !== rowkeys);
            });
            this.visible = false;
            this.handleChangelist(this.pagination, this.serchvalue);
          } else {
            this.loading = false;
            this.visible = false;

            this.$notification["error"]({
              message: "失败",
              description: res.data.msg,
              duration: 1.5
            });
          }
        });
    },

    //打开添加关键词面板
    tjwz() {
      this.$store.state.tjwz = true;
    },
    //关键词采集
    getkeywords() {
      this.axios
        .post(
          "seo/KeyWordsGet.php",
          qs.stringify({
            sqdwid: this.$store.state.bbl_sqdwid
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg,
              duration: 1.5
            });
            this.handleChangelist(this.pagination, this.serchvalue);
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg,
              duration: 1.5
            });
          }
        });
    },

    //客户名称
    flfilterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toUpperCase()
          .indexOf(input.toUpperCase()) >= 0
      );
    },
    //一键查询
    yjcx() {
      this.spin = true;

      this.axios
        .post(
          "seo/BaiduPcRanking.php",
          qs.stringify({
            sqdwid: this.$store.state.bbl_sqdwid
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.spin = false;
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg,
              duration: 1.5
            });
          } else {
            this.spin = false;
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg,
              duration: 1.5
            });
          }
        });
    }
  },
  computed: {
    rowSelection() {
      const { selectedRowKeys } = this;
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = selectedRowKeys;
        }
      };
    }
  },
  created() {
    this.handleChangelist(this.pagination);
  }
};
</script>

<style lang='less'>
.gjcgl_box {
  .mode {
    position: fixed;
    top: 54px;
    width: 100%;
    background: rgba(255, 254, 254, 0.1);
    z-index: 9999;
    height: 1000px;
    .ant-spin-spinning {
      position: fixed;
      display: inline-block;
      opacity: 1;
      top: 222px;
      left: 50%;
    }
  }
  .gl_tjwz {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999999;
    height: 930px;
    .gl_tjym {
      position: absolute;
      width: 80%;
      left: 50%;
      transform: translateX(-50%);
    }
  }
  .header_sele {
    position: absolute;
    top: 55px;
    left: 1% !important;
    z-index: 999;
    text-align: right;
    width: 98%!important;
    background-color: #fff;
    box-shadow: 5px 5px 5px #ccc;
    // height: 50px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px 0!important;
    .add_qy {
      // width: 50%;
      display: inline-block;
      text-align: left;
      padding: 10px 0;
      height: 50px !important;
      button {
        margin: 0 10px;
      }
      .ant-btn-primary {
        background-color: #1890ff !important;
        border: 0 !important;
      }
    }
    .seach {
      display: inline-block;
      .sele {
        position: relative;
        i {
          position: absolute;
          top: 10px;
          right: 8px;
        }
      }
    }
    .list_head {
      display: inline-block;
      .tit {
        font-size: 16px;
      }
      padding: 10px 15px;
      .fl_right {
        .margin {
          margin: 0 5px;
        }
        .xzl_btn:hover {
          border: 0 !important;
          color: #fff !important;
          background: #1890ff !important;
        }
      }
    }
  }
  .glwz {
    width: 98%;
    position: relative;
    top: 147px;
    left: 1%;
    background-color: #fff;
    border: 1px solid #ccc;
    .del_all {
      position: absolute;
      left: 20px;
      bottom: 19px;
    }
    .glwzpic {
      width: 50px;
      height: 50px;
    }
    .ant-table-thead > tr,
    .ant-table-tbody > tr {
      height: 50px !important;
    }
    .del {
    }
  }
}

// .fyloading {
//   position: absolute;
//   width: 90% !important;
//   border: 1px solid #91d5ff;
//   background: rgba(255, 255, 255, 0.5);
//   padding: 30px;
//   height: 800px !important;
//   z-index: 999999 !important;
//   top: 108px;
//   left: 201px;
//   .ant-spin-blur {
//     opacity: 1 !important;
//   }
//   .ant-spin-text {
//     font-size: 18px !important;
//   }

// }
.ant-spin-nested-loading > div > .ant-spin {
  top: 100px !important;
}
.del {
  padding-right: 15px;
  color: #40a9ff;
  cursor: pointer;
}
</style>
